home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / windows / tpwin31.zip / TOOLHELP.PAS < prev    next >
Pascal/Delphi Source File  |  1992-04-06  |  15KB  |  546 lines

  1.  
  2.  
  3. {*******************************************************}
  4. {                                                       }
  5. {       Turbo Pascal for Windows Run-time Library       }
  6. {       Windows 3.1 API Interface Unit                  }
  7. {                                                       }
  8. {       Copyright (c) 1991 Borland International        }
  9. {                                                       }
  10. {*******************************************************}
  11.  
  12. unit TOOLHELP;
  13.  
  14. interface
  15.  
  16. uses WinTypes;
  17.  
  18.  
  19. { General symbols }
  20. const
  21.   max_Data = 11;
  22.   max_Path = 255;
  23.   max_Module_Name =  8 + 1;
  24.   Max_ClassName = 255;
  25.  
  26. { Global heap walking }
  27.  
  28. type
  29.  
  30.   PGlobalInfo = ^TGlobalInfo;
  31.   TGlobalInfo = record
  32.     dwSize: Longint;
  33.     wcItems: Word;
  34.     wcItemsFree: Word;
  35.     wcItemsLRU: Word;
  36.   end;
  37.  
  38.   PGlobalEntry = ^TGlobalEntry;
  39.   TGlobalEntry = record
  40.     dwSize: Longint;
  41.     dwAddress: Longint;
  42.     dwBlockSize: Longint;
  43.     hBlock: THandle;
  44.     wcLock: Word;
  45.     wcPageLock: Word;
  46.     wFlags: Word;
  47.     wHeapPresent: Bool;
  48.     hOwner: THandle;
  49.     wType: Word;
  50.     wData: Word;
  51.     dwNext: Longint;
  52.     dwNextAlt: Longint;
  53.   end;
  54.  
  55. const
  56. { GlobalFirst()/GlobalNext() flags }
  57.   global_All = 0;
  58.   global_LRU = 1;
  59.   global_Free = 2;
  60.  
  61. { TGlobalEntry.wType entries }
  62.   gt_Unknown = 0;
  63.   gt_DGroup = 1;
  64.   gt_Data = 2;
  65.   gt_Code = 3;
  66.   gt_Task = 4;
  67.   gt_Resource = 5;
  68.   gt_Module = 6;
  69.   gt_Free = 7;
  70.   gt_Internal = 8;
  71.   gt_Sentinel = 9;
  72.   gt_BurgerMaster = 10;
  73.  
  74. { If TGlobalEntry.wType = gt_Resource, the following is TGlobalEntry.wData: }
  75.   gd_UserDefined = 0;
  76.   gd_CursorComponent = 1;
  77.   gd_Bitmap = 2;
  78.   gd_IconComponent = 3;
  79.   gd_Menu = 4;
  80.   gd_Dialog = 5;
  81.   gd_String = 6;
  82.   gd_FontDir = 7;
  83.   gd_Font = 8;
  84.   gd_Accelerators = 9;
  85.   gd_RCData = 10;
  86.   gd_ErrTable = 11;
  87.   gd_Cursor = 12;
  88.   gd_Icon = 14;
  89.   gd_NameTable = 15;
  90.   gd_Max_Resource = 15;
  91.  
  92. { TGlobalEntry.wFlags }
  93.   gf_PDB_Owner = $100;    { Low byte us KERNAL flags }
  94.  
  95. function GlobalInfo(lpGlobalInfo: PGlobalInfo): Bool;
  96. function GlobalFirst(lpGlobal: PGlobalEntry; wFlags: Word): Bool;
  97. function GlobalNext(lpGlobal: PGlobalEntry; wFlags: Word): Bool;
  98. function GlobalEntryHandle(lpGlobal: PGlobalEntry; hItem: THandle): Bool;
  99. function GlobalEntryModule(lpGlobal: PGlobalEntry; hModule: THandle; wSeg: Word): Bool;
  100. function GlobalHandleToSel(hMem: THandle): Word;
  101.  
  102. { Local heap walking }
  103. type
  104.   PLocalInfo = ^TLocalInfo;
  105.   TLocalInfo = record
  106.     dwSize: Longint;
  107.     wcItems: Word;
  108.   end;
  109.  
  110.   PLocalEntry = ^TLocalEntry;
  111.   TLocalEntry = record
  112.     dwSize: Longint;
  113.     hHandle: THandle;
  114.     wAddress: Word;
  115.     wSize: Word;
  116.     wFlags: Word;
  117.     wcLock: Word;
  118.     wType: Word;
  119.     hHeap: Word;
  120.     wHeapType: Word;
  121.     wNext: Word;
  122.   end;
  123.  
  124. const
  125.  
  126. { TLocalEntry.wHeapType flags }
  127.   Normal_Heap = 0;
  128.   User_Heap = 1;
  129.   gdi_Heap = 2;
  130.  
  131. { TLocalEntry.wFlags }
  132.   lf_Fixed = 1;
  133.   lf_Free = 2;
  134.   lf_Moveable = 4;
  135.  
  136. { TLocalEntry.wType }
  137.   lt_Normal = 0;
  138.   lt_Free = $FF;
  139.   lt_GDI_Pen = 1;  { lt_GDI_* is for GDI's heap }
  140.   lt_GDI_Brush = 2;
  141.   lt_GDI_Font = 3;
  142.   lt_GDI_Palette = 4;
  143.   lt_GDI_Bitmap = 5;
  144.   lt_GDI_RGN = 6;
  145.   lt_GDI_DC = 7;
  146.   lt_GDI_Disabled_DC = 8;
  147.   lt_GDI_MetaDC = 9;
  148.   lt_GDI_MetaFile = 10;
  149.   lt_GDI_Max = lt_GDI_MetaFile;
  150.   lt_User_Class = 1;  { lt_USER_* is for USER's heap }
  151.   lt_User_Wnd = 2;
  152.   lt_User_String = 3;
  153.   lt_User_Menu = 4;
  154.   lt_User_Clip = 5;
  155.   lt_User_CBox = 6;
  156.   lt_User_Palette = 7;
  157.   lt_User_ED = 8;
  158.   lt_User_BWL = 9;
  159.   lt_User_OwnerDraw = 10;
  160.   lt_User_SPB = 11;
  161.   lt_User_CheckPoint = 12;
  162.   lt_User_DCE = 13;
  163.   lt_User_MWP = 14;
  164.   lt_User_Prop = 15;
  165.   lt_User_LBIV = 16;
  166.   lt_User_Misc = 17;
  167.   lt_User_Atoms = 18;
  168.   lt_User_LockInputState = 19;
  169.   lt_User_HookList = 20;
  170.   lt_User_UserSeeUserDoAlloc = 21;
  171.   lt_User_HotKeyList = 22;
  172.   lt_User_PopUpMenu = 23;
  173.   lt_User_HandleTable = 32;
  174.   lt_User_Max = lt_User_HandleTable;
  175.  
  176. function LocalInfo(lpLocal: PLocalInfo; hHeap: THandle): Bool;
  177. function LocalFirst(lpLocal: PLocalEntry; hHeap: THandle): Bool;
  178. function LocalNext(lpLocal: PLocalEntry): Boolean;
  179.  
  180.  
  181. { Stack Tracing }
  182. type
  183.  
  184.   PStackTraceEntry = ^TStackTraceEntry;
  185.   TStackTraceEntry = record
  186.     dwSize: Longint;
  187.     hTask: THandle;
  188.     wSS: Word;
  189.     wBP: Word;
  190.     wCS: Word;
  191.     wIP: Word;
  192.     hModule: THandle;
  193.     wSegment: Word;
  194.     wFlags: Word;
  195.   end;
  196.  
  197. const
  198. { TStackTraceEntry.wFlags values }
  199.   frame_Far = 0;
  200.   frame_Near = 1;
  201.  
  202. function StackTraceFirst(lpStackTrace: PStackTraceEntry; hTask: THandle): Bool;
  203. function StackTraceCSIPFirst(lpStackTrace: PStackTraceEntry;
  204.                              wSS, wCS, wIP, wBP: Word): Bool;
  205. function StackTraceNext(lpStackTrace: PStackTraceEntry): Bool;
  206.  
  207. { Module list walking }
  208. type
  209.   PModuleEntry = ^TModuleEntry;
  210.   TModuleEntry = record
  211.     dwSize: Longint;
  212.     szModule : array[0..max_Module_Name + 1] of Char;
  213.     hModule: THandle;
  214.     wUsageFlags: Word;
  215.     szExePath: array[0..max_Path + 1] of Char;
  216.     wNext: Word;
  217.   end;
  218.  
  219. function ModuleFirst(lpModule: PModuleEntry): Bool;
  220. function ModuleNext(lpModule: PModuleEntry): Bool;
  221. function ModuleFindName(lpModule: PModuleEntry; lpstrName: PChar): THandle;
  222. function ModuleFindHandle(lpModule: PModuleEntry; hModule: THandle): THandle;
  223.  
  224.  
  225. { Task list walking }
  226. type
  227.  
  228.   PTaskEntry = ^TTaskEntry;
  229.   TTaskEntry = record
  230.     dwSize: Longint;
  231.     hTask: THandle;
  232.     hTaskParent: THandle;
  233.     hInst: THandle;
  234.     hModule: THandle;
  235.     wSS: Word;
  236.     wSP: Word;
  237.     wStackTop: Word;
  238.     wStackMinimum: Word;
  239.     wStackBottom: Word;
  240.     wcEvents: Word;
  241.     hQueue: THandle;
  242.     szModule: array[0..max_Module_Name + 1] of Char;
  243.     wPSPOffset: Word;
  244.     hNext: THandle;
  245.   end;
  246.  
  247. function TaskFirst(lpTask: PTaskEntry): Bool;
  248. function TaskNext(lpTask: PTaskEntry): Bool;
  249. function TaskFindHandle(lpTask: PTaskEntry; hTask: THandle): Bool;
  250. function TaskSetCSIP(hTask: THandle; wCS, wIP: Word): Longint;
  251. function TaskGetCSIP(hTask: THandle): Longint;
  252. function TaskSwitch(hTask: THandle; dwNewCSIP: Longint): Bool;
  253.  
  254. { Window Class enumeration }
  255. type
  256.   PClassEntry = ^TClassEntry;
  257.   TClassEntry = record
  258.     dwSize: Longint;
  259.     hInst: THandle;
  260.     szClassName: array[0..Max_ClassName + 1] of Char;
  261.     wNext: Word;
  262.   end;
  263.  
  264. function ClassFirst(lpClass: PClassEntry): Bool;
  265. function ClassNext(lpClass: PClassEntry): Bool;
  266.  
  267.  
  268. type
  269.  
  270. { Information functions }
  271.   PMemManInfo = ^TMemManInfo;
  272.   TMemManInfo = record
  273.     dwSize: Longint;
  274.     dwLargestFreeBlock: Longint;
  275.     dwMaxPagesAvailable: Longint;
  276.     dwMaxPagesLockable: Longint;
  277.     dwTotalLinearSpace: Longint;
  278.     dwTotalUnlockedPages: Longint;
  279.     dwFreePages: Longint;
  280.     dwTotalPages: Longint;
  281.     dwFreeLinearSpace: Longint;
  282.     dwSwapFilePages: Longint;
  283.     wPageSize: Word;
  284.   end;
  285.  
  286. function MemManInfo(lpEnhMode: PMemManInfo): Bool;
  287.  
  288.  
  289. type
  290.   PSysHeapInfo = ^TSysHeapInfo;
  291.   TSysHeapInfo = record
  292.     dwSize: Longint;
  293.     wUserFreePercent: Word;
  294.     wGDIFreePercent: Word;
  295.     hUserSegment: THandle;
  296.     hGDISegment: THandle;
  297.   end;
  298.  
  299. function SystemHeapInfo(lpSysHeap: PSysHeapInfo): Bool;
  300.  
  301.  
  302. { Interrupt Handling }
  303.  
  304. const
  305.  
  306. { Hooked interrupts }
  307.   int_Div0            = 0;
  308.   int_1               = 1;
  309.   int_3               = 3;
  310.   int_UDInstr         = 6;
  311.   int_StkFault        = 12;
  312.   int_GPFault         = 13;
  313.   int_BadPageFault    = 14;
  314.   int_CtlAltSysRq     = 256;
  315.  
  316. { TOOLHELP Interrupt callbacks registered with InterruptRegister should
  317.  *  always be written in assembly language.  The stack frame is not
  318.  *  compatible with high level language conventions.
  319.  *
  320.  *  This stack frame looks as follows to the callback.  All registers
  321.  *  should be preserved across this callback to allow restarting fault.
  322.  *               ------------
  323.  *               |   Flags  |  [SP + 0Eh]
  324.  *               |    CS    |  [SP + 0Ch]
  325.  *               |    IP    |  [SP + 0Ah]
  326.  *               |  Handle  |  [SP + 08h]
  327.  *               |Exception#|  [SP + 06h]
  328.  *               |    AX    |  [SP + 04h]  AX Saved to allow MakeProcInstance
  329.  *               |  Ret CS  |  [SP + 02h]
  330.  *       SP--->  |  Ret IP  |  [SP + 00h]
  331.  *               ------------
  332.  }
  333.  
  334. type
  335.   TIntCallBack = procedure;
  336.  
  337. function InterruptRegister(hTask: THandle; lpfnIntCallBack: TIntCallBack): Bool;
  338. function InterruptUnRegister(hTask: THandle): Bool;
  339.  
  340. {  Notifications:
  341.      When a notification callback is called, two parameters are passed
  342.      in:  a WORD, wID, and another DWORD, dwData.  wID is one of
  343.      the values nfy_* below.  Callback routines should ignore unrecog-
  344.      nized values to preserve future compatibility.  Callback routines
  345.      are also passed a dwData value.  This may contain data or may be
  346.      a FAR pointer to a structure, or may not be used depending on
  347.      which notification is being received.
  348.  
  349.      In all cases, if the return value of the callback is TRUE, the
  350.      notification will NOT be passed on to other callbacks.  It has
  351.      been handled.  This should be used sparingly and only with certain
  352.      notifications.  Callbacks almost always return FALSE.
  353. }
  354.  
  355. const
  356.  
  357. { nfy_Unknown:  An unknown notification has been returned from KERNEL.  Apps
  358.   should ignore these. }
  359.  
  360.   nfy_Unknown         = 0;
  361.  
  362. { nfy_LoadSeg:  dwData points to a TNFYLoadSeg structure }
  363.  
  364.   nfy_LoadSeg         = 1;
  365.  
  366. type
  367.  
  368.   PNFYLoadSeg = ^TNFYLoadSeg;
  369.   TNFYLoadSeg = record
  370.     dwSize: Longint;
  371.     wSelector: Word;
  372.     wSegNum: Word;
  373.     wType: Word;
  374.     hInstance: THandle;
  375.     lpstrModuleName: PChar;
  376.   end;
  377.  
  378. const
  379.  
  380. { nfy_FreeSeg:  LOWORD(dwData) is the selector of the segment being freed }
  381.  
  382.   nfy_FreeSeg       = 2;
  383.  
  384. { nfy_StartDll:  dwData points to a NFYLOADSEG structure }
  385.   nfy_StartDLL      = 3;
  386.  
  387. type
  388.   PNFYStartDLL = ^TNFYStartDLL;
  389.   TNFYStartDLL = record
  390.     dwSize: Longint;
  391.     hModule: THandle;
  392.     wCS: Word;
  393.     wIP: Word;
  394.   end;
  395.  
  396. const
  397. { nfy_StartTask:  dwData is the CS:IP of the start address of the task }
  398.   nfy_StartTask = 4;
  399.  
  400. { nfy_ExitTask:  The low byte of dwData contains the program exit code }
  401.   nfy_ExitTask = 5;
  402.  
  403. { nfy_DelModule:  LOWORD(dwData) is the handle of the module to be freed }
  404.   nfy_DelModule = 6;
  405.  
  406. { nfy_Rip:  dwData points to a NFYRIP structure }
  407.   nfy_Rip = 7;
  408.  
  409. type
  410.   PNFYRip = ^TNFYRip;
  411.   TNFYRip = record
  412.     dwSize: Longint;
  413.     wIP: Word;
  414.     wCS: Word;
  415.     wSS: Word;
  416.     wBP: Word;
  417.     wExitCode: Word;
  418.   end;
  419.  
  420. const
  421. { nfy_TaskIn:  No data.  Callback should do GetCurrentTask() }
  422.   nfy_TaskIn = 8;
  423.  
  424. { nfy_TaskOut:  No data.  Callback should do GetCurrentTask() }
  425.   nfy_TaskOout = 9;
  426.  
  427. { nfy_InChar:  Return value from callback is used.  If NULL, mapped to 'i' }
  428.   nfy_InChar = 10;
  429.  
  430. { nfy_OutStr:  dwData points to the string to be displayed }
  431.   nfy_OutStr = 11;
  432.  
  433. { nfy_LogError:  dwData points to a TNFYLogError struct }
  434.   nfy_LogError = 12;
  435.  
  436. type
  437.   PNFYLogError = ^TNFYLogError;
  438.   TNFYLogError = record
  439.     dwSize: Longint;
  440.     wErrCode: Word;
  441.     lpInfo: PChar;      { Error code-dependent }
  442.   end;
  443.  
  444. const
  445. { nfy_LogParamError:  dwData points to a TNFYLogParamError struct }
  446.   nfy_LogParamError = 13;
  447.  
  448. type
  449.   PNFYLogParamError = ^TNFYLogParamError;
  450.   TNFYLogParamError = record
  451.     dwSize: Longint;
  452.     wErrCode: Word;
  453.     lpfnErrorAddr : TFarProc;
  454.     lpBadParam: ^Pointer;
  455.   end;
  456.  
  457. const
  458. { NotifyRegister() flags }
  459.   nf_Normal       = 0;
  460.   nf_TaskSwitch   = 1;
  461.   nf_RIP          = 2;
  462.  
  463. type
  464.   TNotifyCallBack = function(wID: Word; dwData: Longint): Bool;
  465.  
  466. function NotifyRegister(hTask: THandle; lpfn: TNotifyCallBack; wFlags:Word): Bool;
  467. function NotifyUnRegister(hTask: THandle): Bool;
  468.  
  469. { Miscellaneous }
  470.  
  471. procedure TerminateApp(hTask: THandle; wFlags: Word);
  472.  
  473. const
  474.  
  475. { TerminateApp() flag values }
  476.   UAE_Box     = 0;
  477.   No_UAE_Box  = 1;
  478.  
  479. function MemoryRead(wSel: Word; dwOffset: Longint; lpBuffer: PChar;
  480.   dwcb: Longint): Longint;
  481. function MemoryWrite(wSel: Word; dwOffset: Longint; lpBuffer: PChar;
  482.   dwcb: Longint): Longint;
  483.  
  484. type
  485.  
  486.   PTimerInfo = ^TTimerInfo;
  487.   TTimerInfo = record
  488.     dwSize: Longint;
  489.     dwmsSinceStart: Longint;
  490.     dwmsThisVM: Longint;
  491.   end;
  492.  
  493. function TimerCount(lpTimer: PTimerInfo): Bool;
  494.  
  495. implementation
  496.  
  497. function GlobalInfo;             external 'TOOLHELP' index  53;
  498. function GlobalFirst;            external 'TOOLHELP' index  51;
  499. function GlobalNext;             external 'TOOLHELP' index  52;
  500. function GlobalEntryHandle;      external 'TOOLHELP' index  54;
  501. function GlobalEntryModule;      external 'TOOLHELP' index  55;
  502. function GlobalHandleToSel;      external 'TOOLHELP' index  50;
  503.  
  504.  
  505. function LocalInfo;              external 'TOOLHELP' index  56;
  506. function LocalFirst;             external 'TOOLHELP' index  57;
  507. function LocalNext;              external 'TOOLHELP' index  58;
  508.  
  509. function StackTraceFirst;        external 'TOOLHELP' index  66;
  510. function StackTraceCSIPFirst;    external 'TOOLHELP' index  67;
  511. function StackTraceNext;         external 'TOOLHELP' index  68;
  512.  
  513. function ModuleFirst;            external 'TOOLHELP' index  59;
  514. function ModuleNext;             external 'TOOLHELP' index  60;
  515. function ModuleFindName;         external 'TOOLHELP' index  61;
  516. function ModuleFindHandle;       external 'TOOLHELP' index  62;
  517.  
  518. function TaskFirst;              external 'TOOLHELP' index  63;
  519. function TaskNext;               external 'TOOLHELP' index  64;
  520. function TaskFindHandle;         external 'TOOLHELP' index  65;
  521. function TaskSetCSIP;            external 'TOOLHELP' index  81;
  522. function TaskGetCSIP;            external 'TOOLHELP' index  82;
  523. function TaskSwitch;             external 'TOOLHELP' index  83;
  524.  
  525. function ClassFirst;             external 'TOOLHELP' index  69;
  526. function ClassNext;              external 'TOOLHELP' index  70;
  527.  
  528. function MemManInfo;             external 'TOOLHELP' index  72;
  529.  
  530. function SystemHeapInfo;         external 'TOOLHELP' index  71;
  531.  
  532. function InterruptRegister;      external 'TOOLHELP' index  75;
  533. function InterruptUnRegister;    external 'TOOLHELP' index  76;
  534.  
  535. function NotifyRegister;         external 'TOOLHELP' index  73;
  536. function NotifyUnRegister;       external 'TOOLHELP' index  74;
  537.  
  538. procedure TerminateApp;          external 'TOOLHELP' index  77;
  539.  
  540. function MemoryRead;             external 'TOOLHELP' index  78;
  541. function MemoryWrite;            external 'TOOLHELP' index  79;
  542.  
  543. function TimerCount;             external 'TOOLHELP' index  80;
  544.  
  545. end.
  546.